package ui.swing.split;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Graphics;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JSplitPane;

public class SplitSample extends JFrame {

	private static final long serialVersionUID = -9090785682911402367L;

	public SplitSample() {
		super("Simple SplitSample Example");
		setSize(400, 400);

		Component c11 = new SimplePanel();
		Component c12 = new SimplePanel();

		JSplitPane spLeft = new JSplitPane(JSplitPane.VERTICAL_SPLIT, c11, c12);
		spLeft.setDividerSize(8);
		spLeft.setDividerLocation(150);
		spLeft.setContinuousLayout(true);

		Component c21 = new SimplePanel();
		Component c22 = new SimplePanel();
		JSplitPane spRight = new JSplitPane(JSplitPane.VERTICAL_SPLIT, c21, c22);
		spRight.setDividerSize(8);
		spRight.setDividerLocation(150);
		spRight.setContinuousLayout(true);

		JSplitPane sp = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, spLeft,
				spRight);
		sp.setDividerSize(8);
		sp.setDividerLocation(200);
		sp.setResizeWeight(0.5);
		sp.setContinuousLayout(false);
		sp.setOneTouchExpandable(true);
		
		getContentPane().add(sp, BorderLayout.CENTER);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setVisible(true);

	}
	
	public static void main(String argv[]) {
		new SplitSample();
	}
}

class SimplePanel extends JPanel {

	private static final long serialVersionUID = 8359181994621545787L;

	public Dimension getPreferredSize() {
		return new Dimension(200, 200);
	}

	public void paintComponent(Graphics g) {
		super.paintComponent(g);
		g.setColor(Color.black);
		Dimension sz = getSize();
		g.drawLine(0, 0, sz.width, sz.height);
		g.drawLine(sz.width, 0, 0, sz.height);
	}
}